<template>
  <div class="card">
    <!-- <div>
      <div>name: {{ name }}</div>
      <div>
        roles:
        <span v-for="role in roles" :key="role">{{ role }}</span>
      </div>
    </div> -->
    <el-card shadow="always">
      <div class="home-name">
        <div class="name w-1">进销存</div>
      </div>
      <el-row :gutter="20" style="margin-top: 15px;">
        <el-col :xs="12" :md="8" :lg="6" v-for="(platform, index) in listData" :key="`platform${index}`" style="padding-bottom: 10px;">
          <div class="home-item">
            <div class="item-title">{{platform.title}}</div>
            <div class="item-font">{{platform.count}} <span style="color: #999; font-size: 15px;"></span></div>
          </div>
        </el-col>
      </el-row>
    </el-card>

    <el-card shadow="always" style="margin-top: 15px;">
      <div class="home-name">
        <div class="name w-2">近七日系统交易金额</div>
      </div>
      <el-row style="margin:40px 45px;">
        <el-col>
          <div id="main" style="width: 1000px;height: 300px;"></div>
        </el-col>
      </el-row>
    </el-card>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
var echarts = require('echarts');

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ])
  },
  data(){
    return{
      charts: '',
      /*  opinion: ["1", "3", "3", "4", "5"],*/
      opinionData: ["3", "2", "4", "4", "5","2","3"],
      listData: [
        { title: '库存总量', count: 2531000 },
        { title: '库存成本（元）', count: 35600000 },
        { title: '客户欠款（元）', count: 3000 },
        { title: '供应商欠款 （元）', count: 0 },
        { title: '销售收入（本月）', count: 0 },
        { title: '商品毛利（本月）', count: 0 },
        { title: '采购金额（本月）', count: 0 },
        { title: '商品种类（本月）', count: 5 }
      ]
    }
  },
  // 调用
  mounted() {
    this.$nextTick(function() {
      this.drawLine('main')
    })
  },
  methods: {
    drawLine(id) {
      this.charts = echarts.init(document.getElementById(id))
      this.charts.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
          show: true,
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          data: ['2020-10-07', '2020-10-08', '2020-10-09', '2020-10-10', '2020-10-11', '2020-10-12', '2020-10-13'],
          axisLine: {
            // 坐标轴轴线相关设置。
            lineStyle: {
              color: '#000'
            }
          },
          name: '日期'
        },
        yAxis: {
          type: 'value',
          axisLine: {
            // 坐标轴轴线相关设置。
            lineStyle: {
              color: '#000'
            }
          }
        },
        series: [{
          name: '交易金额',
          type: 'line',
          stack: '总量',
          // lineStyle: { normal: {
          //   color: '#009688'
          // } },
          data: this.opinionData
        }]
      })
    }
  }
}
</script>

<style scoped>
  .card{
    margin: 20px;
  }
  .home-name{
    height: 42px;
    border-bottom: 1px solid #f6f6f6;
  }
  .home-name .name{
    padding: 0;
    line-height: 42px;
    text-align: center;
    border-bottom: 2px solid #5FB878;
  }
  .home-name .w-1{
    width: 60px;
  }
  .home-name .w-2{
    width: 150px;
  }
  .home-item{
    display: block;
    padding: 10px 15px;
    background-color: #f8f8f8;
    color: #999;
    border-radius: 2px;
    transition: all .3s;
    -webkit-transition: all .3s;
  }
  .home-item .item-font{
    font-style: normal;
    font-size: 30px;
    font-weight: 300;
    color: #009688;
  }
</style>
<!-- 未解决的问题:1.与后台连接，获取到home的数据-日期及交易金额 2.echarts图表的小细节-->
